package com.jt.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.jt.pojo.SysResult;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisCluster;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/11/17
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private JedisCluster jedisCluster;

    @RequestMapping("/findAll")
    public List<User> findAll(){
        return userService.findAll();
    }


    @RequestMapping("/check/{param}/{type}")
    public JSONPObject checuUser(@PathVariable String param, @PathVariable Integer type,String callback){
        return new JSONPObject(callback,SysResult.success(userService.checkUser(param,type)));
    }

    @RequestMapping("/testHttpClent")
    public List<User> testHttpClent(){
        return findAll();
    }

    @RequestMapping("/query/{ticket}")
    public JSONPObject findUserByTicket(@PathVariable String ticket,String callback){
        String UserJson = jedisCluster.get(ticket);
        if (StringUtils.isEmpty(UserJson)){
            return new JSONPObject(callback, SysResult.fail());
        }else {
            return new JSONPObject(callback, SysResult.success(UserJson));
        }

    }
}
